
# 2020/7/15
# encoding=utf-8
from dnac_f import *
"""
功能：
    1.获取所管辖的所有Host主机信息，并打印展示
"""


# -----获取所管辖的host主机信息-----
def get_host(controller):
    try:
        response_dict = controller.get("host")
        # 接下来筛选感兴趣的信息，便于tabulate打印
        host_list = []
        i = 0
        for item in response_dict["response"]:
            i += 1
            host_list.append([i, item["hostIp"], item["hostType"], item["connectedNetworkDeviceIpAddress"]])
        #  利用tabulate以图表的形式打印出来
        print(
            tabulate(host_list, headers=['number', 'host IP', 'type', 'connected to which network device'], tablefmt="rst"))

    except:
        print("Something went wrong with the GET /host request!")
        return None



if __name__ == "__main__":
    my_dnac = dnac()

    response_dict = get_host(my_dnac)